package com.chinaunicom.emergency;

import com.greedystar.generator.entity.Configuration;
import com.greedystar.generator.invoker.SingleInvoker;
import com.greedystar.generator.invoker.base.Invoker;
import com.greedystar.generator.utils.ConfigUtil;

/**
 * @author ZhangHaoxiang
 * @date 2020/8/4
 */
public class CodeGeneration {

    public static void main(String[] args) {
        single();
    }

    public static void single() {
        // 手动配置
        config();
        // 生成单表代码
        Invoker invoker = new SingleInvoker.Builder()
                .setTableName("xxjb_acc_report")
                .setClassName("AccReport")
                .build();
        invoker.execute();
    }

    public static void config() {
        Configuration configuration = new Configuration();
        // 公共配置
        configuration.setAuthor("liuzhuang");
        configuration.setPackageName("com.chinaunicom.emergency");
        configuration.setSwaggerEnable(true);
        configuration.setLombokEnable(true);
        // 数据库连接配置
        Configuration.Db dbConfig = new Configuration.Db();
        dbConfig.setUrl("jdbc:mysql://192.168.220.110:3306/yjgl?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai");
        dbConfig.setUsername("root");
        dbConfig.setPassword("password");
        configuration.setDb(dbConfig);
        // 代码包配置
        Configuration.Path pathConfig = new Configuration.Path();
        pathConfig.setController("action");
        pathConfig.setService("service");
        pathConfig.setEntity("model");
        pathConfig.setDao("repository");
        configuration.setPath(pathConfig);
        // 类名及文件名配置，$s为固定占位符
        Configuration.Name nameConfig = new Configuration.Name();
        nameConfig.setController("$sAction");
        nameConfig.setDao("$sRepository");
        configuration.setName(nameConfig);
        ConfigUtil.setConfiguration(configuration);
    }

}
